using UnityEngine;
using UnityEngine.UI;

namespace Lean.Localization
{
	[ExecuteInEditMode]
	[DisallowMultipleComponent]
	[RequireComponent(typeof(Text))]
	public class LeanLocalizedText : LeanLocalizedBehaviour
	{
		[Tooltip("If PhraseName couldn't be found, this text will be used")]
		public string FallbackText;

		public override void UpdateTranslation(LeanTranslation translation)
		{
			Text component = GetComponent<Text>();
			if (translation != null)
			{
				component.text = translation.Text;
			}
			else
			{
				component.text = FallbackText;
			}
		}

		protected virtual void Awake()
		{
			if (string.IsNullOrEmpty(FallbackText))
			{
				Text component = GetComponent<Text>();
				FallbackText = component.text;
			}
		}
	}
}
